package com.course.api.controller;

import com.course.api.config.Result.Result;
import com.course.api.config.Result.Results;
import com.course.api.entity.Comment;
import com.course.api.service.Impl.CommentServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/comment")
public class CommentController {
    @Autowired
    CommentServiceImpl commentService;

    /**
     * 查询当前课程的论坛数据
     * @param courseId
     * @return List
     */
    @GetMapping("getCommentList")
    public Result  getCommentList(@RequestParam Long courseId) {
        return Results.success(commentService.getCommentInfo(courseId));
    }

    /**
     * 添加评论
     * @param comment
     * @return
     */
    @PostMapping("/add")
    public Result add(@RequestBody Comment comment) {
        commentService.addComment(comment);
        return Results.success();
    }

    /**
     * 删除评论
     * @param id
     * @return
     */
    @DeleteMapping("/delete/{id}")
    public Result remove(@PathVariable(value = "id") Long id) {
        commentService.removeById(id);
        return Results.success();
    }

}
